import time

from selenium.webdriver.common.by import By

from Pages import BasePage

class adminFlightDetailPage(BasePage.Action):
    def __init__(self):
        #LL管家后台改签确认按钮
        self.confirmChange_xpath1 = (By.XPATH, "//span[contains(text(),'改签确认')]")
        #改签确认按钮
        self.confirmChange_xpath = (By.XPATH, "//button[contains(@class,'el-button--primary')]/span[contains(text(),'改签确认')]")
        #改期申请确认--确定按钮
        self.confirm_xpath = (By.XPATH, "//div[@aria-label='改期申请确认']//button[contains(@class,'el-button--primary')]/span[text()='确认']")
        #内部交流备注框--申请改期
        self.innerRemarkApply_xpath = (By.XPATH, "//div[@aria-label='改期申请确认']//textarea[@placeholder='请填写备注信息']")
        #内部交流备注框--处理改期
        self.innerRemarkOperate_xpath = (By.XPATH, "//div[@aria-label='处理改期申请']//textarea[@placeholder='请填写备注信息']")
        #内部交流备注框--处理退票
        self.innerRemarkRefund_xpath = (By.XPATH, "//div[@aria-label='处理退票申请']//textarea[@placeholder='请填写备注信息']")
        #零利润/负利润、确认处理改签申请 确认提交
        self.sure_xpath = (By.XPATH,"/html/body/div[2]/div/div[3]/button[2]/span")
        #LL确认处理改签申请
        self.know_xpath = (By.XPATH,"//button[@class='el-button el-button--default el-button--small el-button--primary ']")
        #改签处理按钮
        self.operateChange_xpath = (By.XPATH, "//button[contains(@class,'el-button--primary')]/span[contains(text(),'改签处理')]")
        #LL我已知晓
        self.Imsure_xpath = (By.XPATH, "//span[contains(text(),'我已知晓')]")
        #
        self.sameTicketNo_xpath = (By.XPATH, "//label/span[contains(text(),'同票号改期')]")
        # 是否外采-否
        self.notOutsourcing_xpath = (By.XPATH, "//label/span[text()='否']")
        #处理改期申请--确定按钮
        self.confirmOperate_xpath = (By.XPATH, "//div[@aria-label='处理改期申请']//button[contains(@class,'el-button--primary')]/span[text()='确认']")
        #LL改签确认按钮
        self.confirmOperate_xpath1 = (By.XPATH, "//button[@class='el-button el-button--primary el-button--mini']//span[text()='确认']")
        #LL改签确定后的确认按钮
        self.newsure_xpath1 = (By.XPATH, "(//button[@class='el-button el-button--primary el-button--mini']//span[text()='确认'])[1]")
        #LL改签后的确定按钮
        self.newsure_xpath1 = (By.XPATH, "(//button[@class='el-button el-button--primary el-button--mini']//span[text()='确认'])[1]")
        #LL改签确认按钮
        self.newsure_xpath2 = (By.XPATH, "(//button[@class='el-button el-button--primary el-button--mini']//span[text()='确认'])[3]")
        #改签确定后的0利润按钮
        self.knowsure_xpath = (By.XPATH, "//button[@class='el-button el-button--default el-button--small el-button--primary ']")
        #LL请确认是否已删除原始PNR？确认处理改签？
        self.downsure_xpath = (By.XPATH, "//button[@class='el-button el-button--default el-button--small el-button--primary ']//span")
        # 退票待确认按钮利润确定按钮
        self.confirmRefund_xpath = (By.XPATH, "//button[contains(@class,'el-button--primary')]/span[contains(text(),' 退票待确认')]")
        #退票确认按钮
        self.confirmRefundButton_xpath =(By.XPATH, "//div[not (contains(@style,'display: none;'))]/div[@aria-label='处理退票申请']//button/span[text()='已确认']")

        #国际机票
        #订单编辑.出票成功
        self.orderEditing_xpath =(By.XPATH, "//button/span[text()=' 订单编辑 ']")
        #航司最大编码
        self.Code_xpath  =(By.XPATH, "//input[@placeholder='请输入航司大编码']")
        #pnr
        self.pnr_xpath =(By.XPATH, "//textarea[@placeholder='请输入PNR信息']")
        #更新订单
        self.updateOrder_xpath =(By.XPATH,"//button/span[text()='更新订单']")
        #确认
        self.sure_xpath =(By.XPATH,"(//button/span[contains(text(),'确定')])[4]")
        #LL请确认是否已删除原始PNR？确认处理改签？
        self.sure_xpath1 = (By.XPATH, "(//button/span[contains(text(),'确定')])[5]")
        #提交出票
        self.Submit_xpath =(By.XPATH,"//button/span[contains(text(),'提交出票')]")
        #线下手工出票
        self.CreateTicket_xpath =(By.XPATH,"(//span[@class='el-radio__inner'])[1]")
        #票号
        self.TicketNumber_xpath =(By.XPATH,"//input[@placeholder='请填写票号']")
        #内部交流
        self.InternalCommunication_xpath =(By.XPATH,"//textarea[@placeholder='请填写备注信息']")

    def confirmChange(self):
        time.sleep(5)
        if self.find_element(*self.confirmChange_xpath1):
            print("confirm change")
            self.smart_click(*self.confirmChange_xpath1)
            time.sleep(2)
            self.find_element(*self.innerRemarkApply_xpath).send_keys("测试订单改期")
            time.sleep(1)
            self.smart_click(*self.newsure_xpath1)
            time.sleep(1)
            self.smart_click(*self.knowsure_xpath)
            time.sleep(1)
            self.smart_click(*self.knowsure_xpath)
            time.sleep(1)
        else:
            return

    def operateChange(self):
        if self.find_element(*self.operateChange_xpath):
            print("operate change")
            # self.smart_click(*self.operateChange_xpath)
            # time.sleep(2)
            # self.find_element(*self.sameTicketNo_xpath).click()
            # time.sleep(1)
            # self.smart_click(*self.notOutsourcing_xpath)
            # time.sleep(5)
            # self.find_element(*self.innerRemarkOperate_xpath).send_keys("测试订单改期处理")
            # time.sleep(1)
            # self.smart_click(*self.confirmOperate_xpath)
            # time.sleep(1)
            # self.smart_click(*self.sure_xpath)
            # time.sleep(1)
            # self.smart_click(*self.know_xpath)
            time.sleep(1)
            self.smart_click(*self.operateChange_xpath)
            time.sleep(2)
            self.smart_click(*self.Imsure_xpath)
            time.sleep(2)
            self.smart_click(*self.notOutsourcing_xpath)
            time.sleep(2)
            self.smart_click(*self.sameTicketNo_xpath)
            time.sleep(2)
            self.smart_click(*self.newsure_xpath2)
            time.sleep(1)
            self.smart_click(*self.knowsure_xpath)
            time.sleep(1)
            self.smart_click(*self.downsure_xpath)
            time.sleep(1)
            # self.smart_click(*self.confirmChange_xpath1)
            # time.sleep(1)
            # self.smart_click(*self.newsure_xpath1)
            # time.sleep(1)
            # self.smart_click(*self.knowsure_xpath)
            # time.sleep(1)
            # self.smart_click(*self.knowsure_xpath)
            # time.sleep(1)
        else:
            return

    def confirmRefund(self):
        if self.find_element(*self.confirmRefund_xpath):
            self.smart_click(*self.confirmRefund_xpath)
            time.sleep(2)
            self.find_element(*self.innerRemarkRefund_xpath).send_keys("测试订单退票")
            time.sleep(1)
            self.find_element(*self.confirmRefundButton_xpath).click()
            time.sleep(1)
            self.smart_click(*self.downsure_xpath)
            time.sleep(1)
            #self.smart_click(*self.sure_xpath)
        else:
            return


    #国际机票 订单编辑
    def ticketingOperate(self):
        if self.find_element(*self.orderEditing_xpath):
            self.smart_click(*self.orderEditing_xpath)
            time.sleep(5)
            self.find_element(*self.Code_xpath).send_keys("123")
            time.sleep(3)
            self.find_element(*self.pnr_xpath).send_keys("测试")
            time.sleep(2)
            self.smart_click(*self.updateOrder_xpath)
            time.sleep(2)
            self.smart_click(*self.sure_xpath)
            time.sleep(10)

        else:
            return

    #国际机票 提交出票
    def SubmitOperate(self):
        if self.find_element(*self.Submit_xpath):
            self.smart_click(*self.Submit_xpath)
            time.sleep(2)
            self.smart_click(*self.CreateTicket_xpath)
            time.sleep(2)
            self.smart_click(*self.TicketNumber_xpath)
            time.sleep(2)
            self.smart_click(*self.notOutsourcing_xpath)
            time.sleep(5)
            self.find_element(*self.InternalCommunication_xpath).send_keys("测试")
            time.sleep(2)
        else:
            return